// API接口统一入口
const apiConfig = require('./config');
const authAPI = require('./auth');
const userAPI = require('./user');
const storageAPI = require('./storage');
const careerPlanAPI = require('./career-plan');
const personalityAPI = require('./personality');
const hobbyAPI = require('./hobby');
const mbtiAPI = require('./mbti');

// 创建API模块
const createAPI = () => {
  return {
    auth: authAPI(apiConfig),
    user: userAPI(apiConfig),
    storage: storageAPI(apiConfig),
    careerPlan: careerPlanAPI(apiConfig),
    personality: personalityAPI(apiConfig),
    hobby: hobbyAPI(apiConfig),
    mbti: mbtiAPI(apiConfig)
  };
};

// API实例
const api = createAPI();

// 导出API模块和配置
module.exports = {
  ...api,
  // 更新API基础URL
  updateBaseURL: (url) => {
    if (url && typeof url === 'string') {
      apiConfig.baseURL = url;
      console.log('API地址已更新:', url);
      
      // 重新创建API实例
      Object.assign(api, createAPI());
    }
  },
  // 获取API配置
  getConfig: () => {
    return { ...apiConfig };
  }
}; 